var dialog = {
    msg:function(msg){
        layui.use(['layer'], function(){
            var layer = layui.layer
            layer.msg("<span style='color:#fff'>"+msg+"</span>",{
                shadeClose: true,
            });
        });
    },
    alert:function(msg,callback){
        layui.use(['layer'], function(){
            var layer = layui.layer
            layer.alert(msg,{
                title:"小采提示您:",
                icon:4,
                shadeClose: true,
                yes:function(){
                    callback();
                },
            });
        });
    },
    sendCode:function(obj,email){
        layui.use(['layer'], function(obj){
            var layer = layui.layer
            layer.alert("验证码已发送,如果未查收请仔细检查一下,是否验证码被拉进垃圾箱",{
                title:"小采提示您:",
                icon:6,
                shadeClose: true,
            });
        });
    },
    success:function(msg,url){
        layui.use(['layer'], function(){
            var layer = layui.layer
            layer.alert(msg,{
                title:"小采提示您:",
                icon:6,
                shadeClose: true,
                yes:function(){
                    window.location.href=url;
                }
            });
        });
    },
    error:function(msg){
        layui.use(['layer'], function(){
            var layer = layui.layer
            layer.alert(msg,{
                title:"小采提示您:",
                icon:5,
                shadeClose: true,
            });
        });
    },
    timeout:function(msg){
        layui.use(['layer'], function(){
            var layer = layui.layer
            layer.alert(msg || '哎呀妈呀,服务器跑偏了',{
                title:"小采提示您:",
                icon:4,
                shadeClose: true,
            });
        });
    },
    iframe:function(title,url,width,height,time){
        layui.use(['layer'], function(){
            var layer = layui.layer
            layer.open({
                type: 2,
                title: title,
                closeBtn: 0, //不显示关闭按钮
                shade: [0.2],
                shadeClose: true,
                area: [width+'px', height+'px'],
                offset: 'rb', //右下角弹出
                time: time, //2秒后自动关闭
                anim: 6,
                content: [url, 'no'],
            });
        })
    },
    submit:function(obj,url,msg,callback){
        layui.use('form', function(){
            var form = layui.form();
            form.on('submit('+obj+')', function(data){
                data.field.id=JSON.parse(getdata('user')).id;
                $.post(url,data.field,function(data){
                    if (data.code == 1) {
                        updatalogin();
                        return dialog.alert(msg,callback)
                    }else{
                        return dialog.alert(data.msg)
                    }
                }).error(function(){
                    dialog.alert('哎呀妈呀,服务器跑偏了')
                });
                return false;
            });
        })
    },
    upload:function(obj,url,beforeSend,successafter){
        layui.use('upload', function(){
            layui.upload({
                elem:obj,
                url:url,
                before:function(data){
                    $(obj).parents('.layui-upload-button').children('.layui-upload-icon').html('<i class="layui-icon">&#xe63d;</i>上传中')
                    beforeSend()
                },
                success:function(data){
                    if (data.code == 1) {
                        $(obj).parents('.layui-upload-button').children('.layui-upload-icon').html('<i class="layui-icon" style="color:#1bdcb5">&#x1005;</i>上传成功')
                        successafter(data)
                    }else{
                        return dialog.error(data.msg)
                    }
                },
            })
        })
    },
}